package com.tensquare.friend.dao;

import com.tensquare.friend.entity.Friend;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface FriendDao extends JpaRepository<Friend,String> {

    /**
     * 查找好友数量
     * @param userid
     * @param friendid
     * @return
     */
    @Query(value = "select count(*) from tb_friend where userid = ?1 and friendid= ?2",nativeQuery = true)
    public int selectCount(String userid,String friendid);

    @Query(value = "select * from tb_friend where userid = ?1 and friendid= ?2",nativeQuery = true)
    public Friend findByUseridAndFriendid(String userid,String friendid);
    /**
     * 同意好友申请
     * @param islike
     * @param userid
     * @param friend
     */
    @Modifying
    @Query(value = "update tb_friend set islike=?1 where userid=?2 and friendid=?3",nativeQuery = true)
    public void updateLike(String islike,String userid,String friend);

    /**
     * 删除好友
     * @param userid
     * @param friendid
     */
    @Modifying
    @Query(value = "delete from tb_friend where userid = ?1 and friendid =?2 ",nativeQuery = true)
    public void deleteFriend(String userid,String friendid);

    @Query(value = "select * from tb_friend where userid= ?1 ",nativeQuery = true)
    public List<Friend> findByUserid(String userid);
}
